package events

import (
	"context"

	"gitee.com/youkelike/zmigrate/migrator"
	"gitee.com/youkelike/zmigrate/pkg/saramax/producer"
	"github.com/IBM/sarama"
)

//go:generate mockgen -source=producer.go -package=evtmocks -destination=mocks/producer.mock.go Producer
type Producer interface {
	ProduceInconsistentEvent(ctx context.Context, event InconsistentEvent) error
}

// 用于全量、增量校验过程的生产者
type FixDataProducer struct {
	*producer.Producer
}

func NewFixDataProducer[T migrator.Entity](client sarama.Client) *FixDataProducer {
	var t T
	topic := "migrator_" + t.TableName()
	p, err := producer.NewSyncProducer(client, topic)
	if err != nil {
		panic(err)
	}
	return &FixDataProducer{Producer: p}
}

func (s *FixDataProducer) ProduceInconsistentEvent(ctx context.Context, evt InconsistentEvent) error {
	return s.ProduceEvent(ctx, evt)
}
